//
//  HomeViewController.m
//  HAODE
//
//  Created by LiYinDi on 15/12/22.
//  Copyright © 2015年 reabam.com. All rights reserved.
//
#import "TSBaseNavigationController.h"
#import "DockItem.h"
#import "HomeViewController.h"
#import "JKSideSlipView.h"
#import "MenuView.h"
#import "MenusModel.h"
#import "ChildrensModel.h"
#import <objc/runtime.h>
#import "RDVTabBarController.h"
#import "LoginViewController.h"
#import "UIButton+UIButtonImageAndText.h" 
#define TableSectionHeaderHeight 60
@interface HomeViewController ()<JKSideSlipViewDelegate,MenuViewDelegate,UIGestureRecognizerDelegate>
{
    JKSideSlipView *_sideSlipView;
    NSMutableArray *selectedTextArray;
    NSMutableArray *selectedCodeArray;
    NSMutableArray *defaultfunCodeArray;
    NSMutableArray *defaultfunNameArray;
    NSMutableArray *funCodeArray;
    NSMutableArray *funNameArray;
    NSMutableArray *modelArray;
    BOOL isDefault;
    NSArray *colorArray;
    BOOL sliderIsOpen;
//    ReabamSingleton*commdity;
    NSDictionary *plistDictionary;
    NSString *isAllow;
    UIView *noDataView;
}
@end

@implementation HomeViewController

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:YES];
//    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
//    }
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"userInfo" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NewVersion" object:nil];
  
}
- (void)viewDidLoad {
    [super viewDidLoad];

    self.extendedLayoutIncludesOpaqueBars = YES;
    if (@available(iOS 11.0, *)) {
        self.tableV.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* CFBundleVersion = [user objectForKey:@"CFBundleVersion"];
    NSLog(@"%@", CFBundleVersion);
    NSLog(@"%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]);
    
    if ([[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"] isEqualToString:CFBundleVersion]) {
        
    }else{
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        [user setObject:[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]  forKey:@"CFBundleVersion"];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"parent0"];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"parent1"];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"parent2"];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"parent3"];
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"parent4"];
        [user synchronize];
    }
    
    isAllow = @"Y";
    
    NSString *timeSp = [user objectForKey:@"timeSp"];
    NSDate *datenow = [NSDate date];
    NSString *currrentTimeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
    
    if (timeSp == nil) {
        isAllow = @"Y";
    } else{
        if (currrentTimeSp.doubleValue >= timeSp.doubleValue+(24*60*60)){
            isAllow = @"Y";
        } else{
            isAllow = @"N";
        }
    }
    
    

    
    // 2017-12-27 去除毛玻璃效果
//    UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 93)];
//    [view setBackgroundColor:[UIColor clearColor]];
//    UIVisualEffect *blurEffect;
//    blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
//    UIVisualEffectView *frostedView;
//    frostedView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
//    frostedView.frame = view.bounds;
//    [view addSubview:frostedView];
//    [_contentView addSubview:view];
    
    
    [_contentView bringSubviewToFront:_topView];
    _topView.backgroundColor = lanse;
//    _topView.alpha = 0.92;
    _dotLabel.layer.cornerRadius=4;
    _dotLabel.layer.masksToBounds=YES;
    
    [self menuView];
    

}
-(void)menuView{
    isDefault=YES;
    sliderIsOpen=NO;
    [_sideSlipView removeFromSuperview];
    _sideSlipView = [[JKSideSlipView alloc]initWithSender:self];
    _sideSlipView.delegate=self;
    _sideSlipView.backgroundColor = [UIColor redColor];
//    _sideSlipView.backgroundColor = shenlan;
    MenuView *menu = [MenuView menuView];
    menu.backgroundColor = lanse;
    menu.delegate=self;
    [menu didSelectRowAtIndexPath:^(id cell, NSIndexPath *indexPath) {
        [_sideSlipView hide];
    }];
    
    UIImage *img=[UIImage imageNamed:@"jingying_new.png"];
    UIImage *tinted = [img rt_tintedImageWithColor:[UIColor whiteColor]];
    [_leftSliderBtn setImage:tinted forState:UIControlStateNormal];
    [_leftSliderBtn setImage:tinted forState:UIControlStateHighlighted];
    
    UIImage *img1=[UIImage imageNamed:@"xiaoxi.png"];
    UIImage *tinted1 = [img1 rt_tintedImageWithColor:[UIColor whiteColor]];
    [_messageBtn setImage:tinted1 forState:UIControlStateNormal];
    [_messageBtn setImage:tinted1 forState:UIControlStateHighlighted];
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSMutableArray* menus = [user objectForKey:@"menus"];
    
    NSLog(@"%@",menus);
    funNameArray =[[NSMutableArray alloc]init];
    funCodeArray =[[NSMutableArray alloc]init];
    defaultfunNameArray =[[NSMutableArray alloc]init];
    defaultfunCodeArray =[[NSMutableArray alloc]init];
    selectedTextArray=[NSMutableArray array];
    selectedCodeArray=[NSMutableArray array];
    modelArray = [NSMutableArray array];
    if (menus.count>0) {
        for (NSDictionary* dic in menus ){
            for (NSDictionary* dic1 in [dic objectForKey:@"childrens"] ){
                [funCodeArray addObject: [dic1 objectForKey:@"funCode"]];
                [funNameArray addObject: [dic1 objectForKey:@"funName"]];
            }
        }
    }
    if (menus.count>0) {
        for (NSDictionary* dic in menus ){
            for (NSDictionary* dic1 in [dic objectForKey:@"childrens"] ){
                if ([[NSString stringWithFormat:@"%@",  [dic1 objectForKey:@"isDisplay"]] isEqualToString:@"1"]) {
                    [defaultfunCodeArray addObject: [dic1 objectForKey:@"funCode"]];
                    [defaultfunNameArray addObject: [dic1 objectForKey:@"funName"]];
                }
            }
        }
    }
    //NSLog(@"funNameArray%@",funNameArray);
    NSMutableArray* itemsArray =[[NSMutableArray alloc]init];
    if (menus.count>0) {
        for (NSDictionary* dic in menus ){
            [itemsArray addObject: [dic objectForKey:@"funName"]];
        }
    }
    menu.items =itemsArray;
    [_sideSlipView setContentView:menu];
    [self.view addSubview:_sideSlipView];
    [self setAutolayOut];
    
    [self setUserSelectedDefault];
}


-(void)NewVersion{
    NSString *str1=[NSString stringWithFormat:@"%d",TARGET_VERSION];
    NSString *plistPath1 = [[NSBundle mainBundle] pathForResource:str1 ofType:@"plist"];
    NSDictionary *dictionary1 = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
    NSString *type = [dictionary1 objectForKey:@"type"];
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:type forKey:@"type"];
    NSLog(@"param====%@",param);
    [HttpRequest requestData1:@"UpGrade/NewVersion" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        NSLog(@"data====%@",severDataDict.dataDict);
        if (isSuccess) {
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
            
                [MBProgressHUD hideProgressHUDInternal:self.view];
                NSString *getVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
                NSString *VersionName = [NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"VersionName"]];
                NSLog(@"num1:%@ is bigger",VersionName);
                NSString *msg = [NSString stringWithFormat:@"%@",[severDataDict.dataDict objectForKey:@"Description"]];
                //从字符A中分隔成几个个元素的数组
                NSArray *getVersionArray = [getVersion componentsSeparatedByString:@"."];
                //从字符A中分隔成几个个元素的数组
                NSArray *VersionNameArray = [VersionName componentsSeparatedByString:@"."];
                // 是否强制更新
                NSString *IsForce = [NSString stringWithFormat:@"%@", [severDataDict.dataDict objectForKey:@"IsForce"]];
                
                if ([getVersion isEqualToString:VersionName]) {
                    
                }else{
                    if (VersionNameArray.count==4) {
                        NSArray*getVersionArray1=@[[NSString stringWithFormat:@"%.f",[getVersionArray[0] doubleValue]*10000000], [NSString stringWithFormat:@"%.f",[getVersionArray[1] doubleValue]*100000],[NSString stringWithFormat:@"%.f",[getVersionArray[2] doubleValue]*1000],[NSString stringWithFormat:@"%.f",[getVersionArray[3]doubleValue]]];
                        NSArray*VersionNameArray1=@[[NSString stringWithFormat:@"%.f",[VersionNameArray[0] doubleValue]*10000000],[NSString stringWithFormat:@"%.f",[VersionNameArray[1] doubleValue]*100000],[NSString stringWithFormat:@"%.f",[VersionNameArray[2] doubleValue]*1000],[NSString stringWithFormat:@"%.f",[VersionNameArray[3]doubleValue]]];
                        
                        NSString*VersionNameStr=[VersionNameArray1 valueForKeyPath:@"@sum.floatValue"];
                        NSString*getVersionStr=[getVersionArray1 valueForKeyPath:@"@sum.floatValue"];
                        NSString *titleMsg = [NSString stringWithFormat:@"发现新版本%@",VersionName];
                        
                        if (VersionNameStr.intValue>=getVersionStr.intValue) {
                            if ([IsForce isEqualToString:@"1"]) {
                                UIAlertController *alert = [UIAlertController alertControllerWithTitle:titleMsg message:msg preferredStyle:UIAlertControllerStyleAlert];
                                
                                [self presentViewController:alert animated:YES completion:nil];
                                
                                [alert addAction:[UIAlertAction actionWithTitle:@"立即更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                    
                                

                                    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/%E7%9D%BF%E6%9C%AC%E7%AE%A1%E7%90%86%E5%8A%A9%E6%89%8B/id1378003966?mt=8"]];
                                }]];
                            } else{
                                
                                if ([isAllow isEqualToString:@"Y"]) {
                                    NSLog(@"num1:%@ is bigger",VersionName);
                                    UIAlertController *alert = [UIAlertController alertControllerWithTitle:titleMsg message:msg preferredStyle:UIAlertControllerStyleAlert];
                                    
                                    [self presentViewController:alert animated:YES completion:nil];
                                    
                                    [alert addAction:[UIAlertAction actionWithTitle:@"稍后再说" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                        
                                        [self getTimeInterval];
                                        
                                    }]];
                                    
                                    [alert addAction:[UIAlertAction actionWithTitle:@"立即更新" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                                        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://itunes.apple.com/cn/app/%E7%9D%BF%E6%9C%AC%E7%AE%A1%E7%90%86%E5%8A%A9%E6%89%8B/id1378003966?mt=8"]];
                                    }]];
                                }
                            }
                        }
                    }
                }
            } else {
                
//                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
//                    TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
//                    [self.navigationController pushViewController:detailViewController animated:YES];
//                } else if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==8801){
//                    BeginDutyViewController *gd = [[BeginDutyViewController alloc] init];
//                    [self.navigationController pushViewController:gd animated:YES];
//                }
            }
        } else {
            [MBProgressHUD hideProgressHUDInternal:self.view];
            [MBProgressHUD showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];
}


// 获取当前时间及时间戳
- (void)getTimeInterval{
    
    NSDate *datenow = [NSDate date];
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
    //    double time = timeSp.doubleValue;
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:timeSp forKey:@"timeSp"];
    [user synchronize];
    // 时间戳
    NSTimeInterval interval    =[timeSp doubleValue];
    NSDate *date               = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter1 setTimeZone:timeZone];
    [formatter1 setDateFormat:@"HH:mm"];
    NSString *dateString       = [formatter1 stringFromDate: date];
    //    self.currentTime = dateString;
    NSLog(@"时间戳是 :%ld", time);
    NSLog(@"对应的年月日: %@",dateString);
    
}



-(void)userInfo{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:@"有消息内容" forKey:@"Left"];
    [user synchronize];
    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        _dotLabel.hidden=NO;//红点提示
    }];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(userInfo) name:@"userInfo" object:Nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(NewVersion) name:@"NewVersion" object:Nil];
    self.navigationController.navigationBarHidden=YES;
    [[self rdv_tabBarController] setTabBarHidden:NO];
//    commdity=[[ReabamSingleton shared]init];
//    commdity.dataMemberDict=nil;
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* parent0 = [user objectForKey:@"parent0"];
    
    
//    if ([[user objectForKey:@"userStatus"] isEqualToString:@"Y"]) {
//        //通过后不需要加载
//    }else{
//        [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTokenId" object:nil];//从新判断后台有木有通过；获取userStatus状态
//    }
    
    
    
    //获取消息数量
//    int totalUnreadCount = [[RCIMClient sharedRCIMClient] getTotalUnreadCount];
//    if (totalUnreadCount>0) {
//
//        _dotLabel.hidden=NO;
//
//    } else if(totalUnreadCount==0) {
//
//        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//        [user setObject:@"已读" forKey:@"Left"];
//        [user synchronize];
//        _dotLabel.hidden=YES;
//    }
//    if ([[user objectForKey:@"Left"]isEqualToString:@"有消息内容"]) {
//        _dotLabel.hidden=NO;
//
//    }else{
//        _dotLabel.hidden=YES;
//    }
//
    //更换帐号从新注册RongYunKey
//    if ([[Global getRongYunToken] length]==0) {
//        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//        NSString* Token = [user objectForKey:@"tokenId"];
//        if (Token.length>0) {
//
//            NSString *str1=[NSString stringWithFormat:@"%d",TARGET_VERSION];
//            //     NSLog(@"str1111===%@",str1);
//            NSString *plistPath1 = [[NSBundle mainBundle] pathForResource:str1
//                                                                   ofType:@"plist"];
//            NSDictionary *dictionary1 = [[NSDictionary alloc] initWithContentsOfFile:plistPath1];
//            //    NSLog(@"dictionary1===%@",dictionary1);
//            NSString *rongYunKey = [dictionary1 objectForKey:@"RongYunKey"];
//            NSLog(@"rdvtabbar init rongyun key");
//            [[RCIM sharedRCIM] initWithAppKey:rongYunKey];//设置容云appKEY
//            [RCIM sharedRCIM].receiveMessageDelegate = self;
//            [self RequestRongYunToken];
//        }
//    }
    if ([[NSString stringWithFormat:@"%@",parent0] length] == 6) {
        isDefault=YES;
        [self menuView];
    }


//    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64+11, ScreenWidth, ScreenHeight-11) style:UITableViewStyleGrouped];
//    tableView.delegate = self;
//    tableView.dataSource = self;
    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
//    tablself.tableVeView.separatorColor = kLineColor;
//    tableView.backgroundColor = [UIColor whiteColor];
    UIView *footerView = [[UIView alloc] init];
    self.tableV.tableFooterView = footerView;
    
 
    
//    self.tableV.contentInset = UIEdgeInsetsMake(0, 0, 20, 0);
//    self.tableView = tableView;
}

//-(void)RequestRongYunToken {
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSString* Token = [user objectForKey:@"tokenId"];
//
//    NSMutableDictionary *param = [NSMutableDictionary new];
//    [param setValue:Token forKey:@"tokenId"];
//    [param setValue:@"user" forKey:@"userType"];
//    NSLog(@"rToken====%@",param);
//    [HttpRequest requestData:@"Chat/RegChat" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
//        // NSLog(@"rToken====%@",severDataDict.dataDict);
//        if (isSuccess) {
//            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
//
//                [[RCIM sharedRCIM] setConnectionStatusDelegate:self];
//                NSString *  rongYunToken=[[severDataDict.dataDict objectForKey:@"chatInfo"] objectForKey:@"chatToken"];
//                [Global setRongYunToken:rongYunToken];
//
//                [[RCIM sharedRCIM] connectWithToken:rongYunToken success:^(NSString *userId) {
//                    [[RCIM sharedRCIM] setUserInfoDataSource:self];
//                } error:^(RCConnectErrorCode status) {
//                    NSLog(@"登陆的错误码为:%ld", (long)status);
//                } tokenIncorrect:^{
//                    NSLog(@"token错误");
//                }];
//            }
//            else{
//
//                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
//                    TheLoginViewController *detailViewController = [[TheLoginViewController alloc] init];
//                    [self.navigationController pushViewController:detailViewController animated:YES];
//                }
//            }
//
//        } else {
//            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//            if ([[user objectForKey:@"userStatus"] isEqualToString:@"E"]) {
//                [Global showTextHudSub:@"请认证门店！" view:self.view];
//            }else{
//                [Global hideProgressHUDInternal:self.view];
//                [Global showTextHudSub:severDataDict.resultStr view:self.view];
//            }
//        }
//    }];
//
//}
//- (void)onRCIMConnectionStatusChanged:(RCConnectionStatus)status {
//    //    NSLog(@"rdvtabbarstatus###^^^===%d",status);
//}
//- (void)getUserInfoWithUserId:(NSString *)userId completion:(void(^)(RCUserInfo* userInfo))completion {
//
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    NSString* Token = [user objectForKey:@"tokenId"];
//    NSMutableDictionary *param = [NSMutableDictionary new];
//    [param setValue:Token forKey:@"tokenId"];
//    [param setValue:userId forKey:@"userId"];
//    NSLog(@"getP=====%@",param);
//    [HttpRequest requestData:@"Chat/GetChatUserInfo" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
//        NSLog(@"getR=====%@",severDataDict.dataDict);
//        if (isSuccess) {
//            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
//                NSString * userNameStr=[[severDataDict.dataDict objectForKey:@"chatInfo"] objectForKey:@"chatUserName"];
//                RCUserInfo *user = [[RCUserInfo alloc]init];
//                user.userId =userId;
//                user.name =userNameStr;
//                user.portraitUri = [[severDataDict.dataDict objectForKey:@"chatInfo"] objectForKey:@"chatUserLogoUrl"];
//                return completion(user);
//            } else{
//
//            }
//        } else {
//            [Global hideProgressHUDInternal:self.view];
//            [Global showTextHudSub:severDataDict.resultStr view:self.view];
//        }
//    }];
//
//}
////自动读取容云当前后台返回时的数据
//- (void)onRCIMReceiveMessage:(RCMessage *)message left:(int)left {
//    int allunread = [[RCIMClient sharedRCIMClient] getTotalUnreadCount];//获取消息数量
//    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
//    [user setObject:@"有消息内容" forKey:@"Left"];
//    [user synchronize];
//    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
//        _dotLabel.hidden=NO;//红点提示
//    }];
//    if([UIApplication sharedApplication].applicationState == UIApplicationStateActive) { //应用在前台
//        //修改app消息界面的参数
//    } else {//应用在后台
//        if(allunread > 0) {
//            [[UIApplication sharedApplication] setApplicationIconBadgeNumber:allunread];//修改应用图标上的数字
//            [UIApplication sharedApplication].applicationIconBadgeNumber = allunread;
//        }
//    }
//}

-(void)setUserSelectedDefault {
    
    [noDataView removeFromSuperview];
    [selectedCodeArray removeAllObjects];
    [selectedTextArray removeAllObjects];
    [modelArray removeAllObjects];
    
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSMutableArray* menus = [user objectForKey:@"menus"];
    
//    NSLog(@"-------  %@",menus);
    funNameArray =[[NSMutableArray alloc]init];
    funCodeArray =[[NSMutableArray alloc]init];
    defaultfunNameArray =[[NSMutableArray alloc]init];
    defaultfunCodeArray =[[NSMutableArray alloc]init];
    selectedTextArray=[NSMutableArray array];
    selectedCodeArray=[NSMutableArray array];
    
    
  
#pragma mark ------

    // 默认
    if (menus.count>0) {
        for (NSDictionary* dic in menus ){
            MenusModel *model = [MenusModel mj_objectWithKeyValues:dic];
            [modelArray addObject:model];
        }
    }
    
    
    if (modelArray.count== 0) {
        return;
    }
    
    NSInteger count = modelArray.count;
    for ( int i=0; i<count; i++) {
        
        MenusModel *modelNew = modelArray[i];
        
        NSString *parentKeyStr= [NSString stringWithFormat:@"parent%ld",(long)i];
        if ([userDefaults dictionaryForKey:parentKeyStr]) {
            isDefault=NO;
        }
        
        NSLog(@"%@", [userDefaults dictionaryForKey:parentKeyStr]);
        NSMutableDictionary *dict=[NSMutableDictionary dictionaryWithDictionary:[userDefaults dictionaryForKey:parentKeyStr]];
        NSMutableArray *array=[NSMutableArray arrayWithArray:[dict objectForKey:@"addOrSubtractARRAY"]];
    
        
        for (int f = 0 ; f < array.count; f++) {
            NSString *str =  array[f];
            ChildrensModel *model1 = modelNew.childrens[f];
            if ([str isEqualToString:@"N"]) {
                model1.isDisplay = @"0";
            } else if([str isEqualToString:@"Y"]){
                model1.isDisplay = @"1";
            } else{
                
            }
        }
    }
    
//    isDefault = NO;
    // 最后总得遍历
    if (isDefault) {  // 默认
        [modelArray removeAllObjects];
        
        if (menus.count>0) {
            for (NSDictionary* dic in menus ){
                MenusModel *model = [MenusModel mj_objectWithKeyValues:dic];
                [modelArray addObject:model];
            }
        }
        
        for (MenusModel *model in modelArray) {
            NSMutableArray *timpArr = [NSMutableArray array];
            
            for (ChildrensModel *model1 in model.childrens) {
                if ([model1.isDisplay isEqualToString:@"0"]) {
                    [timpArr addObject:model1];
                }
            }
            
            for (ChildrensModel *model1  in timpArr) {
                if ([model.childrens containsObject:model1]) {
                    [model.childrens removeObject:model1];
                }
            }
        }
    } else{
        for (MenusModel *model in modelArray) {
            NSMutableArray *timpArr = [NSMutableArray array];
            
            for (ChildrensModel *model1 in model.childrens) {
                if ([model1.isDisplay isEqualToString:@"0"]) {
                    [timpArr addObject:model1];
                }
            }
           
            for (ChildrensModel *model1  in timpArr) {
                if ([model.childrens containsObject:model1]) {
                    [model.childrens removeObject:model1];
                }
            }
        }
    }

    
    // 最后总的处理数据源
//    NSLog(@"modelArray == %@", modelArray);
    NSMutableArray *timpArr = [NSMutableArray array];
    for (MenusModel *model in modelArray) {
        if (model.childrens.count == 0) {
            [timpArr addObject:model];
        }
    }
    for (MenusModel *model  in timpArr) {
        if ([modelArray containsObject:model]) {
            [modelArray removeObject:model];
        }
    }
    
    
    if (modelArray.count == 0) {
//        _sideSlipView.alpha = 0;
        noDataView=[[UIView alloc]initWithFrame:CGRectMake(0, (ScreenHeight-64-49)/2-60, ScreenWidth, 180)];
        
        UIImageView*noImage=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth/2-60, -6, 120, 60)];
        noImage.image=[UIImage imageNamed:@"meiyoucaidan"];
        [noDataView addSubview:noImage];
        UILabel*noLabel=[[UILabel alloc]initWithFrame:CGRectMake(0,noImage.bottom+12, ScreenWidth, 14)];
        noLabel.text=@"请添加更多快捷菜单!";
        noLabel.textColor=zhonghuiColor;
        noLabel.font=[UIFont systemFontOfSize:14];
        noLabel.textAlignment=NSTextAlignmentCenter;
        [noDataView addSubview:noLabel];
        
        UIButton *btn = [[UIButton alloc] init];
        btn.frame = CGRectMake((ScreenWidth-74)*0.5, noLabel.bottom+28, 74, 30);
        [btn setTitle:@"去添加" forState:UIControlStateNormal];
        [btn setTitleColor:lanse forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        btn.layer.borderWidth = 0.5;
        btn.layer.borderColor = lanse.CGColor;
        btn.layer.cornerRadius = 4.0;
        btn.layer.masksToBounds = YES;
        [btn addTarget:self action:@selector(meauAdd:) forControlEvents:UIControlEventTouchUpInside];
        [noDataView addSubview:btn];
        
        
//        UIButton *btn1 = [[UIButton alloc] init];
//        btn1.frame = CGRectMake((ScreenWidth-100)*0.5, noLabel.bottom+10, 100, 100);
//        [btn1 setTitle:@"" forState:UIControlStateNormal];
//        [btn1 setTitleColor:lanse forState:UIControlStateNormal];
//        btn1.backgroundColor = [UIColor redColor];
//        [btn1 addTarget:self action:@selector(meauAdd:) forControlEvents:UIControlEventTouchUpInside];
//        [noDataView addSubview:btn1];
        
        
        [self.tableV addSubview:noDataView];
    }
    
    [self.tableV reloadData];
    
#pragma mark ------
    

}

- (void)meauAdd:(UIButton *)sender{
    NSLog(@"按钮被点击");
//    sliderIsOpen = YES;
//    [self leftSliderBtnClick:sender];
    
    if (sliderIsOpen) {
//        _sideSlipView.alpha= 1;
        [[self rdv_tabBarController] setTabBarHidden:NO];
        _homeBtnView.hidden=YES;
        [_topView setBackgroundColor:lanse];
        [_sideSlipView hide];
        sliderIsOpen=NO;

    } else {
//        _sideSlipView.alpha= 1;
        [[self rdv_tabBarController] setTabBarHidden:YES];
        _homeBtnView.hidden=NO;
        [_tableV setContentOffset:CGPointMake(0, 0)];
        [_topView setBackgroundColor:lanse];
        [_sideSlipView show];
        sliderIsOpen=YES;

    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    return view;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return TableSectionHeaderHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
   
    MenusModel *model = modelArray[section];
    
    UIView *headerView = [[UIView alloc] init];
    headerView.frame = CGRectMake(0, 0, ScreenWidth, TableSectionHeaderHeight);
    headerView.backgroundColor = [UIColor whiteColor];
    
    
    UIView *dotView = [[UIView alloc] init];
    dotView.frame = CGRectMake(15, ((TableSectionHeaderHeight-8)*0.5)+7.5, 8, 8);
    dotView.backgroundColor = [UIColor whiteColor];
    [headerView addSubview:dotView];
    dotView.layer.borderColor = lanse3.CGColor;
    dotView.layer.borderWidth = 2.0;
    dotView.layer.cornerRadius = 4;
    dotView.layer.masksToBounds = YES;
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.frame = CGRectMake(dotView.right+6, 15, ScreenWidth-30, TableSectionHeaderHeight-15);
    titleLabel.text = model.funName;
//    titleLabel.font = [UIFont systemFontOfSize:17.0 ];
    titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
    titleLabel.textColor = [UIColor colorWithHexString:@"141e34"];
    [headerView addSubview:titleLabel];
    
    return headerView;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return modelArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    CGFloat height = 0;
    
    
    MenusModel *model = modelArray[indexPath.section];
    
    height = model.childrens.count /5 * 120 +120 ;
    
//    NSLog(@"%f", height);
//    if (indexPath.section == 0) {
//        height = array.count %3 * 120 +120 ;
//    } else if (indexPath.section == 1){
//        height = 120 ;
//    }
    return height;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellId = @"cellId";
//    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
//    if (cell == nil) {
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
//    }
    
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    cell.accessoryType = UITableViewCellAccessoryNone;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    CGFloat height = 0;
    MenusModel *model = modelArray[indexPath.section];
    height = model.childrens.count /5 * 120 +120 ;
    
    UIView *parentsView = [[UIView alloc] init];
    parentsView.frame = CGRectMake(20, 0, ScreenWidth-40, height);
//    parentsView.backgroundColor = [UIColor redColor];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.frame = CGRectMake(15, parentsView.bottom-0.5, ScreenWidth-30, 0.5);
    lineView.backgroundColor = qianhuiColor;
    [cell.contentView addSubview:lineView];
    [cell.contentView addSubview:parentsView];
    
    //每个Item宽高
    CGFloat W = parentsView.width /4;
    CGFloat H = 120;
    //每行列数
    NSInteger rank = 4;
    //每列间距
    CGFloat rankMargin = 0;
    //每行间距
    CGFloat rowMargin = 0;
    //Item索引 ->根据需求改变索引
    
    NSUInteger index = model.childrens.count;
    for (int i = 0 ; i< index; i++) {
        
        ChildrensModel *modelC = model.childrens[i];
        
        //Item X轴
        CGFloat X = (i % rank) * (W + rankMargin);
        //Item Y轴
        NSUInteger Y = (i / rank) * (H +rowMargin);
        //Item top
        NSString *title = modelC.funName;
        DockItem *speedView = [[DockItem alloc] init];
        [speedView setTitle:title forState:UIControlStateNormal];
        
        
        NSString *vcStr = modelC.funCode;
        NSString *subIconStr = nil;
        if ([vcStr isEqualToString:@"my:group:mgr"]) {
            
            subIconStr=@"wodeshanghu_";
            
        } else if ([vcStr isEqualToString:@"summary:sales:mgr"]){
            
            subIconStr=@"xiaoshougaikuang_";
            
        } else if ([vcStr isEqualToString:@"customOrder:sales:mgr"]){
            
            subIconStr=@"mendiankedan_";
            
        } else if ([vcStr isEqualToString:@"itemVolume:sales:mgr"]){
            
            subIconStr=@"shangpinxiaoliang_";
            
        } else if ([vcStr isEqualToString:@"typeVolume:sales:mgr"]){
            
            subIconStr=@"pinleixiaoliang_";
            
        } else if ([vcStr isEqualToString:@"summary:member:mgr"]){
            
            subIconStr=@"huiyuangaikuang_";
            
        } else if ([vcStr isEqualToString:@"active:member:mgr"]){
            
            subIconStr=@"huiyuanhuoyuedu_";
            
        } else if ([vcStr isEqualToString:@"order:b2b:mgr"]){
            
            subIconStr=@"dingdantongji_";
            
        } else if ([vcStr isEqualToString:@"refund:b2b:mgr"]){
            
            subIconStr=@"tuihuotongji_";
            
        } else if ([vcStr isEqualToString:@"customOrder:b2b:mgr"]){
            subIconStr=@"kedanfenxi_";
            
        }
       
        
        
        [speedView setImage:[UIImage imageNamed:subIconStr] forState:UIControlStateNormal];
        speedView.imageView.contentMode = UIViewContentModeCenter;
        
//        int R = (arc4random() % 4) ;
//        NSLog(@"%d", R);
//        speedView.imageView.backgroundColor =colorArray[R];
        [speedView addTarget:self action:@selector(menuBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        speedView.frame = CGRectMake(X, Y, W, H);
        [parentsView addSubview:speedView];
    }
    
    UIView *lineView1 = [[UIView alloc] init];
    lineView1.frame = CGRectMake(10, height -0.5, ScreenWidth-20, 0.5);
    lineView1.backgroundColor = [UIColor colorWithHexString:@"eeeeee"];
    [cell.contentView addSubview:lineView1];
    return cell;
}

- (void)menuBtnClick:(UIButton *)sender{

    [_sideSlipView hide];
    sliderIsOpen=NO;
    
    NSLog(@"%@", sender.titleLabel.text);
    NSString *vcStr = sender.titleLabel.text;
    // 我的商户 wodeshanghu
    if ([vcStr isEqualToString:@"我的商户"]) {
        NSString *vcStr=@"MyStoreViewController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
        // 销售概况  xiaoshougaikuang
    }else if ([vcStr isEqualToString:@"销售概况"]){
        NSString *vcStr=@"SellConditionViewController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
        // 门店客单 mendiankedan
    }else if ([vcStr isEqualToString:@"门店客单"]){
        
        NSString *vcStr=@"StoreDataAnalyseViewController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
        // 商品销量 shangpinxiaoliang
    }else if ([vcStr isEqualToString:@"商品销量"]){
        
        NSString *vcStr=@"ProductSellTotalViewController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
        // 品类销量 pinleixiaoliang
    }else if ([vcStr isEqualToString:@"品类销量"]){
        
        NSString *vcStr=@"kindSellTotalViewController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
        
    // 会员概况 huiyuangaikuang
    } else if ([vcStr isEqualToString:@"会员概况"]){

        NSString *vcStr=@"MemberProfileViewController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];

        // 会员活跃度 huiyuanhuoyuedu
    }
//    else if ([vcStr isEqualToString:@"会员活跃度"]){
//
//        NSString *vcStr=@"DeliverylistViewController";
//        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
//        [self.navigationController pushViewController:vc animated:YES];
//
//        // 订单统计 dingdantongji
//    }
    else if ([vcStr isEqualToString:@"订货统计"]){

        NSString *vcStr=@"OrderGoodsStatisticsController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];

        // 退货统计 tuihuotongji
    }else if ([vcStr isEqualToString:@"退货统计"]){
        NSString *vcStr=@"SalesReturnStatisticsController";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        [self.navigationController pushViewController:vc animated:YES];

        // 客单分析 kedanfenxi
    }

    else{
        NSString *vcStr=@"";
        UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
        if (vc==nil) {
            //显示弹出框列表选择
            UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"尚未开通"        preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                //响应事件
                NSLog(@"action = %@", action);
            }];
            [alert addAction:saveAction];
            [self presentViewController:alert animated:YES completion:nil];
        }else {
            [self.navigationController pushViewController:vc animated:YES];
        }
        
    }
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

}

-(void)subTableviwAddOrSubtractClickAtHome {
    
    [self setUserSelectedDefault];
}
- (void) didSelectCellAtChildIndex:(NSInteger)childIndex withInParentCellIndex:(NSInteger)parentIndex {

    [_sideSlipView hide];
    sliderIsOpen=NO;
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    if ([[user objectForKey:@"menus"]count] > 0) {
        NSString *vcStr=[[[[[user objectForKey:@"menus"] objectAtIndex:parentIndex]objectForKey:@"childrens" ]objectAtIndex:childIndex]objectForKey:@"funCode"];

        // 我的商户 wodeshanghu
        if ([vcStr isEqualToString:@"my:group:mgr"]) {
            NSString *vcStr=@"MyStoreViewController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];

        // 销售概况  xiaoshougaikuang
        }else if ([vcStr isEqualToString:@"summary:sales:mgr"]){
            NSString *vcStr=@"SellConditionViewController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
            
        // 门店客单 mendiankedan
        }else if ([vcStr isEqualToString:@"customOrder:sales:mgr"]){
            
            NSString *vcStr=@"StoreDataAnalyseViewController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        
        // 商品销量 shangpinxiaoliang
        }else if ([vcStr isEqualToString:@"itemVolume:sales:mgr"]){
            
            NSString *vcStr=@"ProductSellTotalViewController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
            
        // 品类销量 pinleixiaoliang
        }else if ([vcStr isEqualToString:@"typeVolume:sales:mgr"]){

            NSString *vcStr=@"kindSellTotalViewController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        
        // 会员概况 huiyuangaikuang
        }else if ([vcStr isEqualToString:@"summary:member:mgr"]){
            
            NSString *vcStr=@"MemberProfileViewController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        
        // 会员活跃度 huiyuanhuoyuedu
        }
//        else if ([vcStr isEqualToString:@"active:member:mgr"]){
//            
//            NSString *vcStr=@"DeliverylistViewController";
//            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
//            [self.navigationController pushViewController:vc animated:YES];
//        
        // 订单统计 dingdantongji
//        }
     else if ([vcStr isEqualToString:@"order:b2b:mgr"]){
            
            NSString *vcStr=@"OrderGoodsStatisticsController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        
        // 退货统计 tuihuotongji
        }else if ([vcStr isEqualToString:@"refund:b2b:mgr"]){
            NSString *vcStr=@"SalesReturnStatisticsController";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        
        // 客单分析 kedanfenxi
        }  else{
//            [_sideSlipView hide];
//            sliderIsOpen=YES;
            NSString *vcStr=@"";
            UIViewController * vc = (UIViewController*)[[NSClassFromString(vcStr) alloc] init];
            if (vc==nil) {
//                UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"尚未开通" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
//                [alert show];
                
               
                    //显示弹出框列表选择
                    UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"尚未开通"        preferredStyle:UIAlertControllerStyleAlert];
//
//                    UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) {
//                        //响应事件
//                        NSLog(@"action = %@", action);
//                    }];
//                    UIAlertAction*deleteAction = [UIAlertAction actionWithTitle:@"删除" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * action) {
//                             //响应事件
//                             NSLog(@"action = %@", action);
//                    }];
                    UIAlertAction* saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                       //响应事件
                       NSLog(@"action = %@", action);
                    }];
                    [alert addAction:saveAction];
//                    [alert addAction:cancelAction];
//                    [alert addAction:deleteAction];
                    [self presentViewController:alert animated:YES completion:nil];
                
                
            }else {
                [self.navigationController pushViewController:vc animated:YES];
            }
            
        }
        
    }
}
-(void)hideSlider {
    [[self rdv_tabBarController] setTabBarHidden:NO];
    _homeBtnView.hidden=YES;
    [_topView setBackgroundColor:lanse];
    [UIView animateWithDuration:0.3 animations:^{
        [_contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left) ;
            make.width.equalTo(self.view.mas_width);
            make.bottom.equalTo(self.view.mas_bottom) ;
            make.top.equalTo(self.view.mas_top) ;
        }];
    } completion:^(BOOL finished) {

    }];
    
    sliderIsOpen=NO;
}
-(void)showSlider {
    
//    [_tableV setContentOffset:CGPointMake(0, 49)];
    sliderIsOpen=YES;
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    _homeBtnView.hidden=YES;
    [_topView setBackgroundColor:shenlan];
    
    [_contentView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left).with.offset(250);
        make.width.equalTo(self.view.mas_width);
        make.bottom.equalTo(self.view.mas_bottom);
        make.top.equalTo(self.view.mas_top);
    }];
    
}
-(void)menuViewHomeBtnClick {
    
    sliderIsOpen=NO;
    [_sideSlipView hide];
}
-(void)menuViewConfirmCancelClick {
    
    [_sideSlipView hide];
    LoginViewController* Login=[[LoginViewController alloc]init];
    [self.navigationController pushViewController:Login animated:YES];
    
}
- (IBAction)leftSliderBtnClick:(id)sender {
    
    if (sliderIsOpen) {
        [[self rdv_tabBarController] setTabBarHidden:NO];
        _homeBtnView.hidden=YES;
        [_topView setBackgroundColor:lanse];
        [_sideSlipView hide];
        sliderIsOpen=NO;
        
    } else {
        
        [[self rdv_tabBarController] setTabBarHidden:YES];
        _homeBtnView.hidden=NO;
        [_topView setBackgroundColor:lanse];
        [_sideSlipView show];
        sliderIsOpen=YES;
    }
}
- (void)addBtnClick{
    if (sliderIsOpen) {
        [[self rdv_tabBarController] setTabBarHidden:NO];
        _homeBtnView.hidden=YES;
        [_topView setBackgroundColor:lanse];
        [_sideSlipView hide];
        sliderIsOpen=NO;
        
    } else {
        
        [[self rdv_tabBarController] setTabBarHidden:YES];
        _homeBtnView.hidden=NO;
        [_tableV setContentOffset:CGPointMake(0, 0)];
        [_topView setBackgroundColor:lanse];
        [_sideSlipView show];
        sliderIsOpen=YES;
        
    }
    
}

- (IBAction)messageBtnClick:(id)sender {
    
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];//修改应用图标上的数字
    [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    if ([[user objectForKey:@"userStatus"] isEqualToString:@"E"]) {
//        ToBindCompanyViewController * Login=[[ToBindCompanyViewController alloc]init];
//        Login.viewSat=@"The original road";
//        [self.navigationController pushViewController:Login animated:YES];
    }else if ([[user objectForKey:@"userStatus"] isEqualToString:@"W"]){
        [[self rdv_tabBarController] setSelectedIndex:2];//my
        
    }else{
//        MessageViewController *messageVC = [[MessageViewController alloc] init];
//        [self.navigationController pushViewController:messageVC animated:YES];
    }
}

-(void)setAutolayOut
{
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.width.equalTo(self.view.mas_width);
        make.bottom.equalTo(self.view.mas_bottom);
        make.top.equalTo(self.view.mas_top);
    }];
    
    
    if (is_iPhoneX) {
        
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_contentView.mas_left);
            make.width.equalTo(_contentView.mas_width);
            make.height.equalTo(@88);
            make.top.equalTo(_contentView.mas_top) ;
        }];
        
        [_homeBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left);
            make.bottom.equalTo(self.view.mas_bottom).offset(-TabbarSafeBottomMargin);
            make.height.equalTo(@83);
            make.width.equalTo(_contentView.mas_width);
            
        }];
        
    } else{
        
        
        [_topView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_contentView.mas_left);
            make.width.equalTo(_contentView.mas_width);
            make.height.equalTo(@64);
            make.top.equalTo(_contentView.mas_top) ;
        }];
        
        [_homeBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.view.mas_left); 
            make.bottom.equalTo(self.view.mas_bottom);
            make.height.equalTo(@49);
            make.width.equalTo(_contentView.mas_width);
            
        }];
    }
    
    
//    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left);
//        make.width.equalTo(self.view.mas_width);
//        make.bottom.equalTo(self.view.mas_bottom);
//        make.top.equalTo(self.view.mas_top) ;
//    }];
//
//    [_homeBtnView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view.mas_left);
//        make.bottom.equalTo(self.view.mas_bottom);
//        make.height.equalTo(@49);
//        make.width.equalTo(_contentView.mas_width);
//
//    }];
    
   
    
    
    // 标题
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_contentView.mas_left);
        make.width.equalTo(_contentView.mas_width);
        make.height.equalTo(@44);
        make.bottom.equalTo(_topView.mas_bottom);
    }];
    
    
    // 右侧按钮
    [_leftSliderBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_contentView.mas_left).with.offset(10);
        make.bottom.equalTo(_topView.mas_bottom);
        make.height.equalTo(@44);
        make.width.equalTo(@40);
    }];
    
    // 消息按钮
    [_messageBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_contentView.mas_right).with.offset(-10);
        make.bottom.equalTo(_topView.mas_bottom);
        make.height.equalTo(@44);
        make.width.equalTo(@30);
    }];
    
    // 消息红点
    [_dotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_contentView.mas_right).with.offset(-12);
        make.bottom.equalTo(_topView.mas_bottom).with.offset(-25.5);
        make.height.equalTo(@8);
        make.width.equalTo(@8); 
    }];

    [_homeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_homeBtnView.mas_left).with.offset(0) ;
        make.bottom.equalTo(_homeBtnView.mas_bottom);
        make.height.equalTo(@49);
        make.width.equalTo(_contentView.mas_width).dividedBy(3);
        
    }];
    
    [_bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_homeBtnView.mas_left);
        make.bottom.equalTo(_homeBtn.mas_top);
        make.height.equalTo(@0.5);
        make.width.equalTo(_contentView.mas_width);
        
    }];
    
    
    [_zhanTingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_homeBtn.mas_right)  ;
        make.bottom.equalTo(_homeBtnView.mas_bottom);
        make.height.equalTo(@49);
        make.width.equalTo(_contentView.mas_width).dividedBy(3);
        
    }];
    
    
    [_tableV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.width.equalTo(self.view.mas_width);
        make.top.equalTo(self.view.mas_top).offset(StatusBarAndNavigationBarHeight);
        make.bottom.equalTo(self.view.mas_bottom).offset(-TabbarSafeBottomMargin);// 
    }];
    
}

@end
